package sunda.oa;

import localhost.services.WorkflowData.WorkflowDataPortTypeProxy;

import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        System.out.println( "Hello World!" );
        /** 根据用户工号获取用户基本详情信息 */
//        ExtHrmresourcesPortTypeProxy extHrmresourcesPortTypeProxy = new ExtHrmresourcesPortTypeProxy();
//        Map<String, Object> map = new HashMap<>();
//        try {
//        	AnyType2AnyTypeMapEntry[] sss = extHrmresourcesPortTypeProxy.getUserInfoByWorkcode("999947");
//        	JSONArray array = (JSONArray) JSON.toJSON(sss);
//        	//System.out.println("======" + array.toString());
//        	for (int i = 0; i < array.size(); i ++){
//        	    System.out.println(array.getJSONObject(i));
//        	    map.put(array.getJSONObject(i).getString("key"), array.getJSONObject(i).getString("value"));
//            }
//
//		} catch (Exception e) {
//			// TODO: handle exception
//			e.printStackTrace();
//		}
        

        /** 查询请购单提交 OA 后的 OA 日志信息 */
        WorkflowDataPortTypeProxy proxy = new WorkflowDataPortTypeProxy();
        try {
            com.sunda.business.soa.hr.po.WorkflowLogs[] hhLogs = proxy.getWorkflowLogsByReqid("838295");
            List<Map<String, Object>> mapList = new ArrayList<>();
            for(com.sunda.business.soa.hr.po.WorkflowLogs hh : hhLogs) {
				Map<String, Object> map = new HashMap<>();
				map.put("requestId", hh.getRequestid());
                map.put("opter", hh.getOpter());
                map.put("nodeName", hh.getNodename());
                map.put("operateTime", hh.getOperatetime());
                map.put("optStatus", hh.getOptstatus());
                map.put("receiveTime", hh.getReceivetime());
                System.out.println(map.toString());
                mapList.add(map);
			}
            System.out.println(mapList);
        } catch (RemoteException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        
        /** 查询所有有效用户基本详情信息 */
//        ExtHrmresourcesPortTypeProxy extHrmresourcesPortTypeProxy = new ExtHrmresourcesPortTypeProxy();
//        try {
//			for (AnyType2AnyTypeMapEntry[] ss : extHrmresourcesPortTypeProxy.getUserInfos()) {
//				JSONArray array = (JSONArray) JSON.toJSON(ss);
//				System.out.println("======" + array);
//				
//			}
//		} catch (Exception e) {
//			// TODO: handle exception
//			e.printStackTrace();
//		}
        
        
        /** 根据流程编号，追踪流程在OA审批过程记录 */
//        try {
//        	WorkflowData workflowData = new WorkflowData();
//            WorkflowDataPortType workflowDataPortType = workflowData.getWorkflowDataHttpPort();
//            ArrayOfWorkflowLogs logs = workflowDataPortType.getWorkflowLogsByReqid("838295");
//            if (logs != null) {
//            	for(WorkflowLogs log : logs.getWorkflowLogs()) {
//            		System.out.println(JSON.toJSONString(log));
//                	//System.out.println("log ===== " + log.getOpter().getValue() + "  ：  " + log.getNodename().getValue());
//                }
//            }
//		} catch (Exception e) {
//			e.printStackTrace();
//			// TODO: handle exception
//		}
        
        
        
        /** 创建OA流程示例 */
//        ExtHrmresourcesPortTypeProxy proxy = new ExtHrmresourcesPortTypeProxy();
//		RequestServicePortTypeProxy wfproxy = new RequestServicePortTypeProxy();
//		try {
//			int userId = proxy.getUseridByWorkcode("0112448");
//			System.out.println("OAID ==== " + userId);
//
//			RequestInfo reqinfo = new RequestInfo();
//
//			reqinfo.setCreatorid(String.valueOf(userId));// OAID（需提示的那个审批人
//			reqinfo.setWorkflowid("512");// workflowid 测试系统 为462 正式系统待提供
//			reqinfo.setRequestlevel("0");// 紧急程度 默认
//			reqinfo.setRemindtype("0"); // 默认
//			reqinfo.setIsNextFlow("0"); // 默认
//			reqinfo.setDescription("流程标题");
//
//
//			MainTableInfo wmi = new MainTableInfo();
//			Property[] wrti = new Property[1];
//
//			wrti[0] = new Property();
//			wrti[0].setName("eprosreqid");
//			wrti[0].setValue("123456");
//			wmi.setProperty(wrti);
//			reqinfo.setMainTableInfo(wmi);
//
//			// 生成待办 ，返回待办id
//			String reqid = wfproxy.createRequest(reqinfo);
//			System.out.println("reqid ==== " + reqid); //     返回大于0 的数字则调用成功
//		} catch (RemoteException e) {
//			System.out.println(e.getMessage());
//		}
        
    }
}

/**
 * {
	"nodename": {
		"declaredType": "java.lang.String",
		"globalScope": false,
		"name": {
			"localPart": "nodename",
			"namespaceURI": "http://po.hr.soa.business.sunda.com",
			"prefix": ""
		},
		"nil": false,
		"scope": "sunda.oa.workflowdata.WorkflowLogs",
		"typeSubstituted": false,
		"value": "1、提交申请"
	}
}
 */
